<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class BadlinksController extends AppController {

    var $name = 'Badlinks';
    var $components = array(
        'Session'
    );

    var $uses = array(
        'Badlinks'
    );

    function index() {

        $this->set('title_for_layout', Configure::read('site_name') . ' - Report Badlinks');
        $page = array_key_exists('page', $this->params['named']) ? $this->params['named']['page'] : 1;
        $search = !empty($this->params['form']['search']) ? $this->params['form']['search'] : false;
        $conditions = array();

        //search
        if ($search) {
            $conditions['OR'] = array(
                'Badlinks.game_id LIKE' => "%$search%",
            );
        }
        $this->paginate = array(
            'conditions' => $conditions,
            'limit' => Configure::read('limit_list'),
            'order' => array(
                'Badlinks.id' => 'DESC'
            ),
        );
        $data = $this->paginate('Badlinks');
        $this->set('total', $this->params['paging']['Badlinks']['count']);
        $this->set('data', $data);
        $this->set('limit_page', $this->paginate['limit']);
        $this->set('start_page', $page);
    }

    function remove() {
        $conditions = array(
            "{$this->Badlinks->alias}.{$this->Badlinks->primaryKey} IN (" . implode(',', $this->params['form']['cid']) . ')'
        );
        if ($this->Badlinks->deleteAll($conditions, true)) {
            $this->Session->setFlash(sprintf("Xóa thành công %d nội dung", sizeof($this->params['form']['cid'])), 'msg', array(), 'msg');
        } else {
            $this->Session->setFlash('Không thể xóa', 'msg', array(), 'error');
        }
        $this->redirect(array('action' => 'index'));
    }

}

?>
